From 9f6a8a78ba3cfb6db253105384eb3b8969c9068e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 7 Oct 2016 15:01:38 +0300 Subject: [PATCH] Remove ExecEngine abstraction --- src/bin/bench.rs | 1 - src/bin/build.rs | 1 - src/bin/doc.rs | 1 - src/bin/install.rs | 1 - src/bin/run.rs | 1 - src/bin/rustc.rs | 1 - src/bin/rustdoc.rs | 1 - src/bin/test.rs | 1 - src/cargo/ops/cargo_compile.rs | 8 ++----- src/cargo/ops/cargo_package.rs | 1 - .../ops/cargo_rustc/{engine.rs => command.rs} | 24 +------------------ src/cargo/ops/cargo_rustc/context.rs | 6 ----- src/cargo/ops/cargo_rustc/job_queue.rs | 2 +- src/cargo/ops/cargo_rustc/mod.rs | 10 ++++---- src/cargo/ops/cargo_test.rs | 6 ++--- src/cargo/ops/mod.rs | 2 +- 16 files changed, 12 insertions(+), 55 deletions(-) rename src/cargo/ops/cargo_rustc/{engine.rs => command.rs} (75%) diff --git a/src/bin/bench.rs b/src/bin/bench.rs index d9abefe40..d5bc21dd4 100644 --- a/src/bin/bench.rs +++ b/src/bin/bench.rs @@ -89,7 +89,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { all_features: options.flag_all_features, no_default_features: options.flag_no_default_features, spec: &options.flag_package, - exec_engine: None, release: true, mode: ops::CompileMode::Bench, filter: ops::CompileFilter::new(options.flag_lib, diff --git a/src/bin/build.rs b/src/bin/build.rs index 0357fe080..eb6673c2f 100644 --- a/src/bin/build.rs +++ b/src/bin/build.rs @@ -85,7 +85,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { all_features: options.flag_all_features, no_default_features: options.flag_no_default_features, spec: &options.flag_package, - exec_engine: None, mode: ops::CompileMode::Build, release: options.flag_release, filter: ops::CompileFilter::new(options.flag_lib, diff --git a/src/bin/doc.rs b/src/bin/doc.rs index c1841c20a..c250dde22 100644 --- a/src/bin/doc.rs +++ b/src/bin/doc.rs @@ -81,7 +81,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { all_features: options.flag_all_features, no_default_features: options.flag_no_default_features, spec: &options.flag_package, - exec_engine: None, filter: ops::CompileFilter::new(options.flag_lib, &options.flag_bin, &empty, diff --git a/src/bin/install.rs b/src/bin/install.rs index b5d67fd41..319b9bdf6 100644 --- a/src/bin/install.rs +++ b/src/bin/install.rs @@ -109,7 +109,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { all_features: options.flag_all_features, no_default_features: options.flag_no_default_features, spec: &[], - exec_engine: None, mode: ops::CompileMode::Build, release: !options.flag_debug, filter: ops::CompileFilter::new(false, &options.flag_bin, &[], diff --git a/src/bin/run.rs b/src/bin/run.rs index f5055b5eb..f9ce05731 100644 --- a/src/bin/run.rs +++ b/src/bin/run.rs @@ -82,7 +82,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { all_features: options.flag_all_features, no_default_features: options.flag_no_default_features, spec: &[], - exec_engine: None, release: options.flag_release, mode: ops::CompileMode::Build, filter: if examples.is_empty() && bins.is_empty() { diff --git a/src/bin/rustc.rs b/src/bin/rustc.rs index fa9334f5b..831031984 100644 --- a/src/bin/rustc.rs +++ b/src/bin/rustc.rs @@ -103,7 +103,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { all_features: options.flag_all_features, no_default_features: options.flag_no_default_features, spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]), - exec_engine: None, mode: mode, release: options.flag_release, filter: ops::CompileFilter::new(options.flag_lib, diff --git a/src/bin/rustdoc.rs b/src/bin/rustdoc.rs index 587046200..df3e4886b 100644 --- a/src/bin/rustdoc.rs +++ b/src/bin/rustdoc.rs @@ -90,7 +90,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { all_features: options.flag_all_features, no_default_features: options.flag_no_default_features, spec: &options.flag_package.map_or(Vec::new(), |s| vec![s]), - exec_engine: None, release: options.flag_release, filter: ops::CompileFilter::new(options.flag_lib, &options.flag_bin, diff --git a/src/bin/test.rs b/src/bin/test.rs index 410c0a2c4..ed487aa42 100644 --- a/src/bin/test.rs +++ b/src/bin/test.rs @@ -123,7 +123,6 @@ pub fn execute(options: Options, config: &Config) -> CliResult> { all_features: options.flag_all_features, no_default_features: options.flag_no_default_features, spec: &options.flag_package, - exec_engine: None, release: options.flag_release, mode: mode, filter: filter, diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 0767e9e46..7b6cb1b71 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -24,13 +24,12 @@ use std::collections::HashMap; use std::path::PathBuf; -use std::sync::Arc; use core::registry::PackageRegistry; use core::{Source, SourceId, PackageSet, Package, Target}; use core::{Profile, TargetKind, Profiles, Workspace, PackageIdSpec}; use core::resolver::{Method, Resolve}; -use ops::{self, BuildOutput, ExecEngine}; +use ops::{self, BuildOutput}; use sources::PathSource; use util::config::Config; use util::{CargoResult, profile, human, ChainError}; @@ -53,8 +52,6 @@ pub struct CompileOptions<'a> { /// Filter to apply to the root package to select which targets will be /// built. pub filter: CompileFilter<'a>, - /// Engine which drives compilation - pub exec_engine: Option>>, /// Whether this is a release build or not pub release: bool, /// Mode for this compile. @@ -159,7 +156,7 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>, let CompileOptions { config, jobs, target, spec, features, all_features, no_default_features, release, mode, message_format, - ref filter, ref exec_engine, + ref filter, ref target_rustdoc_args, ref target_rustc_args } = *options; @@ -247,7 +244,6 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>, let mut ret = { let _p = profile::start("compiling"); let mut build_config = try!(scrape_build_config(config, jobs, target)); - build_config.exec_engine = exec_engine.clone(); build_config.release = release; build_config.test = mode == CompileMode::Test; build_config.json_errors = message_format == MessageFormat::Json; diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 2001c6c87..55f8dd64f 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -293,7 +293,6 @@ fn run_verify(ws: &Workspace, tar: &File, opts: &PackageOpts) -> CargoResult<()> all_features: false, spec: &[], filter: ops::CompileFilter::Everything, - exec_engine: None, release: false, message_format: ops::MessageFormat::Human, mode: ops::CompileMode::Build, diff --git a/src/cargo/ops/cargo_rustc/engine.rs b/src/cargo/ops/cargo_rustc/command.rs similarity index 75% rename from src/cargo/ops/cargo_rustc/engine.rs rename to src/cargo/ops/cargo_rustc/command.rs index ec892392c..d49951c8a 100644 --- a/src/cargo/ops/cargo_rustc/engine.rs +++ b/src/cargo/ops/cargo_rustc/command.rs @@ -2,32 +2,10 @@ use std::collections::HashMap; use std::ffi::{OsStr, OsString}; use std::fmt; use std::path::Path; -use std::process::Output; -use util::{CargoResult, ProcessError, ProcessBuilder, process}; +use util::{CargoResult, ProcessBuilder, process}; use util::Config; -/// Trait for objects that can execute commands. -pub trait ExecEngine: Send + Sync { - fn exec(&self, CommandPrototype) -> Result<(), ProcessError>; - fn exec_with_output(&self, CommandPrototype) -> Result; -} - -/// Default implementation of `ExecEngine`. -#[derive(Clone, Copy)] -pub struct ProcessEngine; - -impl ExecEngine for ProcessEngine { - fn exec(&self, command: CommandPrototype) -> Result<(), ProcessError> { - command.into_process_builder().exec() - } - - fn exec_with_output(&self, command: CommandPrototype) - -> Result { - command.into_process_builder().exec_with_output() - } -} - /// Prototype for a command that must be executed. #[derive(Clone)] pub struct CommandPrototype { diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index 7cbd2149f..e7f57fe57 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -16,7 +16,6 @@ use super::fingerprint::Fingerprint; use super::layout::{Layout, LayoutProxy}; use super::links::Links; use super::{Kind, Compilation, BuildConfig}; -use super::{ProcessEngine, ExecEngine}; #[derive(Clone, Copy, Eq, PartialEq, Hash)] pub struct Unit<'a> { @@ -34,7 +33,6 @@ pub struct Context<'a, 'cfg: 'a> { pub packages: &'a PackageSet<'cfg>, pub build_state: Arc, pub build_explicit_deps: HashMap, (PathBuf, Vec)>, - pub exec_engine: Arc>, pub fingerprints: HashMap, Arc>, pub compiled: HashSet>, pub build_config: BuildConfig, @@ -72,9 +70,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> { None => None, }; - let engine = build_config.exec_engine.as_ref().cloned().unwrap_or({ - Arc::new(Box::new(ProcessEngine)) - }); let current_package = try!(ws.current()).package_id().clone(); Ok(Context { host: host_layout, @@ -88,7 +83,6 @@ impl<'a, 'cfg> Context<'a, 'cfg> { compilation: Compilation::new(config), build_state: Arc::new(BuildState::new(&build_config)), build_config: build_config, - exec_engine: engine, fingerprints: HashMap::new(), profiles: profiles, compiled: HashSet::new(), diff --git a/src/cargo/ops/cargo_rustc/job_queue.rs b/src/cargo/ops/cargo_rustc/job_queue.rs index 53bad6b78..d02d841b8 100644 --- a/src/cargo/ops/cargo_rustc/job_queue.rs +++ b/src/cargo/ops/cargo_rustc/job_queue.rs @@ -13,7 +13,7 @@ use util::{CargoResult, profile, internal}; use super::{Context, Kind, Unit}; use super::job::Job; -use super::engine::CommandPrototype; +use super::command::CommandPrototype; /// A management structure of the entire dependency graph to compile. /// diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 280b6c05d..1efcc2b0c 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -18,14 +18,14 @@ use self::job_queue::JobQueue; pub use self::compilation::Compilation; pub use self::context::{Context, Unit}; -pub use self::engine::{CommandPrototype, CommandType, ExecEngine, ProcessEngine}; +pub use self::command::{CommandPrototype, CommandType}; pub use self::layout::{Layout, LayoutProxy}; pub use self::custom_build::{BuildOutput, BuildMap, BuildScripts}; -mod context; +mod command; mod compilation; +mod context; mod custom_build; -mod engine; mod fingerprint; mod job; mod job_queue; @@ -42,7 +42,6 @@ pub struct BuildConfig { pub requested_target: Option, pub target: TargetConfig, pub jobs: u32, - pub exec_engine: Option>>, pub release: bool, pub test: bool, pub doc_all: bool, @@ -467,7 +466,6 @@ fn rustdoc(cx: &mut Context, unit: &Unit) -> CargoResult { let name = unit.pkg.name().to_string(); let build_state = cx.build_state.clone(); let key = (unit.pkg.package_id().clone(), unit.kind); - let exec_engine = cx.exec_engine.clone(); Ok(Work::new(move |state| { if let Some(output) = build_state.outputs.lock().unwrap().get(&key) { @@ -476,7 +474,7 @@ fn rustdoc(cx: &mut Context, unit: &Unit) -> CargoResult { } } state.running(&rustdoc); - exec_engine.exec(rustdoc).chain_error(|| { + rustdoc.into_process_builder().exec().chain_error(|| { human(format!("Could not document `{}`.", name)) }) })) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index e8f155a34..d73ec8103 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -1,6 +1,6 @@ use std::ffi::{OsString, OsStr}; -use ops::{self, ExecEngine, ProcessEngine, Compilation}; +use ops::{self, Compilation}; use util::{self, CargoResult, CargoTestError, ProcessError}; use core::Workspace; @@ -98,7 +98,7 @@ fn run_unit_tests(options: &TestOptions, shell.status("Running", cmd.to_string()) })); - if let Err(e) = ExecEngine::exec(&ProcessEngine, cmd) { + if let Err(e) = cmd.into_process_builder().exec() { errors.push(e); if !options.no_fail_fast { break @@ -175,7 +175,7 @@ fn run_doc_tests(options: &TestOptions, try!(config.shell().verbose(|shell| { shell.status("Running", p.to_string()) })); - if let Err(e) = ExecEngine::exec(&ProcessEngine, p) { + if let Err(e) = p.into_process_builder().exec() { errors.push(e); if !options.no_fail_fast { return Ok(errors); diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index 442d8c5a8..4d646ea30 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -5,7 +5,7 @@ pub use self::cargo_read_manifest::{read_manifest,read_package,read_packages}; pub use self::cargo_rustc::{compile_targets, Compilation, Layout, Kind, Unit}; pub use self::cargo_rustc::{Context, LayoutProxy}; pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig}; -pub use self::cargo_rustc::{CommandType, CommandPrototype, ExecEngine, ProcessEngine}; +pub use self::cargo_rustc::{CommandType, CommandPrototype}; pub use self::cargo_run::run; pub use self::cargo_install::{install, install_list, uninstall}; pub use self::cargo_new::{new, init, NewOptions, VersionControl}; -- 2.30.2